﻿IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'proc_cm_SaveDailyWord')
BEGIN
    PRINT 'Dropping Procedure proc_cm_SaveDailyWord'
    DROP  Procedure  proc_cm_SaveDailyWord
END
GO

PRINT 'Creating Procedure proc_cm_SaveDailyWord'
GO

CREATE PROCEDURE [dbo].[proc_cm_SaveDailyWord]
	@pDailywordId uniqueidentifier
	, @pHtmlPageId uniqueidentifier
	, @pWeeknumId int
	, @pWeekStartDt datetime
	, @pWeekEndDt datetime
	, @pPublishedInd bit
	, @pAssignmentMondayTxt nvarchar(1000)
	, @pAssignmentTuesdayTxt nvarchar(1000)
	, @pAssignmentWednesdayTxt nvarchar(1000)
	, @pAssignmentThursdayTxt nvarchar(1000)
	, @pAssignmentFridayTxt nvarchar(1000)
	, @pAssignmentSaturdayTxt nvarchar(1000)
	, @pAssignmentSundayTxt nvarchar(1000)
AS
BEGIN
	SET NOCOUNT ON

	UPDATE
		[dbo].[tbl_dailyword]
	SET
		[html_page_id] = @pHtmlPageId
		, [weeknum_id] = @pWeeknumId
		, [week_start_dt] = @pWeekStartDt
		, [week_end_dt] = @pWeekEndDt
		, [published_ind] = @pPublishedInd
		, [assignment_monday_txt] = @pAssignmentMondayTxt
		, [assignment_tuesday_txt] = @pAssignmentTuesdayTxt
		, [assignment_wednesday_txt] = @pAssignmentWednesdayTxt
		, [assignment_thursday_txt] = @pAssignmentThursdayTxt 
		, [assignment_friday_txt] = @pAssignmentFridayTxt 
		, [assignment_saturday_txt] = @pAssignmentSaturdayTxt 
		, [assignment_sunday_txt] = @pAssignmentSundayTxt 
	WHERE
		[dailyword_id] = @pDailywordId

	IF @@ROWCOUNT = 0
	BEGIN
		INSERT INTO [dbo].[tbl_dailyword]
		(
			[dailyword_id]
			,[html_page_id]
			,[weeknum_id]
			,[week_start_dt]
			,[week_end_dt]
			,[published_ind]
			,[assignment_monday_txt]
			,[assignment_tuesday_txt]
			,[assignment_wednesday_txt]
			,[assignment_thursday_txt] 
			,[assignment_friday_txt] 
			,[assignment_saturday_txt] 
			,[assignment_sunday_txt] 
		)
		VALUES
		(
			@pDailywordId
			,@pHtmlPageId
			,@pWeeknumId
			,@pWeekStartDt
			,@pWeekEndDt
			,@pPublishedInd
			,@pAssignmentMondayTxt
			,@pAssignmentTuesdayTxt
			,@pAssignmentWednesdayTxt
			,@pAssignmentThursdayTxt
			,@pAssignmentFridayTxt
			,@pAssignmentSaturdayTxt
			,@pAssignmentSundayTxt
		)
	END
END
GO

GRANT EXEC ON dbo.proc_cm_SaveDailyWord TO PUBLIC
GO
